package cn.pzhu.controller.admin;

import cn.pzhu.controller.BaseController;
import cn.pzhu.model.Category;
import cn.pzhu.model.Role;
import cn.pzhu.services.admin.CategoryServices;
import cn.pzhu.services.admin.RoleServices;

import java.util.List;

/**
 * Created by dongp on 2016/4/25.
 */
public class CategoryController extends BaseController {

    private CategoryServices categoryServices = new CategoryServices();

    public void index() {
        render("category.jsp");
    }

    public void ajaxQuery() {
        List<Category> categories = categoryServices.ajaxQuery();
        renderJson(categories);
    }

    public void ajaxQueryPage() {
        String pageNumber = getPara("pageNumber");
        String pageSize = getPara("pageSize");
        String search = getPara("search","");
        List atrrs = categoryServices.ajaxQueryPage(pageNumber, pageSize, search);
        renderJson(atrrs);
    }

    public void ajaxUpdate() {
        String categoryID = getPara("categoryID");
        String typeName = getPara("typeName");
        Integer typeVal = getParaToInt("typeVal", 0);

        boolean result = categoryServices.ajaxUpdate(categoryID, typeName, typeVal);
        if(result) {
            setAttr("msg","success");// 该返回的成功信息前台暂时没用
        }else {
            setAttr("msg","failue");
        }

        render("category.jsp");
    }

    public void ajaxAdd() {
        String typeName = getPara("typeName");
        Integer typeVal = getParaToInt("typeVal",0);

        boolean result = categoryServices.ajaxAdd(typeName, typeVal);
        render("category.jsp");
    }

    public void ajaxDel() {
        String categoryID = getPara("categoryID");
        boolean result = categoryServices.ajaxDel(categoryID);

        render("category.jsp");
    }

}
